struct TreeNode
{
    int val;
    TreeNode *left;
    TreeNode *right;

    TreeNode(int x)
        : val(x), left(nullptr), right(nullptr)
    {
    }
};

class Solution
{
public:
    long long pre = -1E10;
    bool isValidBST(TreeNode *root)
    {
        if (nullptr == root)
        {
            return true;
        }

        if (!isValidBST(root->left))
        {
            return false;
        }
        if (root->val <= pre)
        {
            return false;
        }
        pre = root->val;

        return isValidBST(root->right);
    }
};